package com.mf.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.mf.entity.User;
import com.mf.result.Result;
import com.mf.service.IUserService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;


/**
* <p>
    *  前端控制器
    * </p>
*
* @author mf
* @since 2024-06-08
*/
@RestController
@RequestMapping("/user")
public class UserController {
    @Resource
    private IUserService userService;

    /**
     * 新增用户
     */
    @PostMapping("/add")
    public Result<Boolean> add(@Valid @RequestBody User user)
    {
        return Result.success(userService.save(user));
    }

    /**
     * 删除用户
     */
    @GetMapping("/delete")
    public Result<Boolean> delete(@RequestParam("id") String id)
    {
        return Result.success(userService.removeById(id));
    }

    /**
     * 查询所有启用用户
     */
    @GetMapping("/findAllUser")
    public Result<List<User>> findAllUser()
    {
        return Result.success(userService.list(new LambdaQueryWrapper<User>().eq(User::getStatus, 0)));
    }
}
